import '../models/progress_info.dart';
import 'package:flutter/material.dart';

class ProgressPromptBar extends StatefulWidget {
  const ProgressPromptBar({super.key, required this.notifier});
  final ValueNotifier<ProgressInfo> notifier;
  @override
  State<ProgressPromptBar> createState() => ProgressPromptBarState();
}

class ProgressPromptBarState extends State<ProgressPromptBar> {
  @override
  void initState() {
    super.initState();
    widget.notifier.addListener(_update);
  }

  @override
  void dispose() {
    widget.notifier.removeListener(_update);
    super.dispose();
  }

  void _update() {
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    ProgressInfo progressInfo = widget.notifier.value;
    return Row(
      children: [
        if (progressInfo.finished == false)
          const SizedBox(
            width: 16,
            height: 16,
            child: CircularProgressIndicator(strokeWidth: 1),
          ),
        if (progressInfo.prompt != null) Text(progressInfo.prompt!),
      ],
    );
  }
}
